#pragma once
#include"noncopyable.h"
#include"Channel.h"
#include"Socket.h"
#include<functional>

class Eventloop;
class InetAddress;

class Acceptor:noncopyable
{
    public:
        using NewConnectionCallback=std::function<void(int sockfd,const InetAddress&)>;
        Acceptor(Eventloop *loop,const InetAddress &listenAddr,bool reuseport);
        ~Acceptor();
        void setNewConnectionCallback(const NewConnectionCallback &cb)
        {
            newConnectionCallback_=cb;
        }
        bool listening() const {return listening_;}
        void listen();
    private:
        void handleRead();
        Eventloop *loop_;//Accepter用的就是用户定义的那个baseloop
        Socket acceptSocket_;
        Channel acceptChannel_;
        NewConnectionCallback newConnectionCallback_;
        bool listening_;
};